﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>主材月度加工计划</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <link rel="stylesheet" href="/InSiteWebApplication/Content/webuploader/webuploader.css" />
    <style type="text/css">
        .l-btn2
        {
            border: #d2d2d2 1px solid;
            font-family: Tahoma, Helvetica;
            font-size: 10px;
            cursor: pointer;
            font-weight: 500;
            text-decoration: none;
            height: 26px;
            color: #fff;
            background: #02bfbf;
        }
        .l-btn2:hover
        {
            color: #fff;
            background: #05d2d2;
        }
        .btnNews
        {
            height: 20px;
            width: 50px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 9px;
            margin: 2px 2px;
            cursor: pointer;
            color: Black;
            border-radius: 1px;
            box-shadow: 0px 1px 0px #3d6b93;
            line-height: 10px;
            text-align: center;
            text-decoration: none;
            transition: background-color 0.15s ease-in-out;
        }
    </style>
</head>
<body>
    <div id="mainSec">
        <div class="panelSection">
            <div class="easyui-panel " title="查询区域" style="padding: 0px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <form id="queryForm" action="">
                <div style="margin: 3px 0px 0px 3px">
                    <div style="float: left;">
                        <div class="divLabel" style="margin-bottom: 5px">
                            生产订单：</div>
                        <input id="txtMfgOrderName_qf" name="mfgOrderName" class="easyui-textbox" style="width: 120px;
                            height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            零件号：</div>
                        <input id="txtProductName_qf" name="productName" class="easyui-textbox" style="width: 120px;
                            height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            计划开始日期：</div>
                        <input id="txtPlanStartDate" name="planStartDate" class="easyui-datebox" type="text"
                            style="width: 120px; height: 22px" data-options='editable:false' />
                        -
                        <input id="txtPlanEndDate" name="planEndDate" class="easyui-datebox" type="text"
                            style="width: 120px; height: 22px;" data-options='editable:false' />
                    </div>
                    <div style="float: left; margin-left: 20px">
                        <a id="btnSearch" href='#' class="easyui-linkbutton" style="margin-top: 16px; width: 80px">
                            查询</a> <a id="btnReset" href='#' class="easyui-linkbutton" style="margin-top: 16px;
                                margin-left: 5px;">重置</a>
                    </div>
                    <div style="clear: both">
                    </div>
                </div>
                </form>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="订单数据" style="padding: 1px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px; width: 99%;">
                    <a id="btnExportOrder" href='#' class="easyui-linkbutton" style="width: 100px; height: 22px;">
                        导出</a>
                </div>
                <div style="margin: 3px 0px 3px 3px; width: 99%; height: 40%;">
                    <table id="gdMfgOrderInfo" class="easyui-datagrid" style="width: 100%; height: 100%;"
                        data-options="fitColumns:true,rownumbers:true">
                    </table>
                </div>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="月度生产准备需求" style="padding: 1px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px; width: 99%;">
                    <a id="btnExport" href='#' class="easyui-linkbutton" style="width: 100px; height: 22px;">
                        导出</a>
                </div>
                <div style="margin: 3px 0px 3px 3px; width: 99%; height: 40%;">
                    <table id="gdMaterialInfo" class="easyui-datagrid" style="width: 100%; height: 100%;"
                        data-options="fitColumns:true,rownumbers:true">
                    </table>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/webuploader/webuploader.js"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
创建人：zhangrj
日期：2024-06-12
描述：主材月度加工计划js
*/
var page = {
    rootPath: getRootPath(), //网站根路径
    url: getRootPath() + "/Ashx/ReBiaoConainer/MainMaterialsConsumeHandler.ashx",
    commonUrl: getRootPath() + "/Ashx/CommonHandler.ashx",
    //初始化页面
    init: function () {
        page.bind();
    },
    //页面事件绑定
    bind: function () {
        //列表加载
        $("#gdMfgOrderInfo").datagrid({
            columns: [[
                 { field: 'MFGORDERNAME', title: '生产订单', width: 150 },
                 { field: 'PRODUCTNAME', title: '零件号', width: 150 },
                 { field: 'PRODUCTDESC', title: '零件名称', width: 150 },
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'QTY', title: '数量', width: 80 },
                 { field: 'PLANNEDSTARTDATE', title: '计划开始日期', width: 100,formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }},
                 { field: 'PLANNEDCOMPLETIONDATE', title: '计划结束日期', width: 100,formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     } }
                ]]
        });
        //列表加载
        $("#gdMaterialInfo").datagrid({
            columns: [[
                 { field: 'MaterialName', title: '物料编码', width: 120 },
                 { field: 'MaterialDesc', title: '物料名称', width: 120 },
                 { field: 'CalculateUnit', title: '计量单位', width: 80 },
                 { field: 'MaterialTechStandard', title: '技术标准', width: 100 },
                 { field: 'MaterialVendormodel', title: '牌号', width: 100 },
                 { field: 'MaterialSpecification', title: '规格', width: 100 },
                 { field: 'MaterialCategory', title: '类别', width: 100 },
                 { field: 'DemandQty', title: '需求数量', width: 100 },
                 { field: 'InventoryQty', title: '库存数量', width: 100 },
                 { field: 'GapQty', title: '缺口数量', width: 100 }
                ]]
        });
        //查询按钮
        $('#btnSearch').on("click", function () {
            page.clearPage(false,true)
            page.searchData();
        });
        //清除按钮
        $('#btnReset').on("click", function () {
            page.clearPage(true, true);
        });
        //导出主材月度计划
        $('#btnExport').on("click", function () {
                var rows = $("#gdMaterialInfo").datagrid("getRows");
                if (rows.length === 0) {
                    displayMessage("请查询数据", false);
                    return false;
                }
                FileDownLoad(page.url, { action: "ExportMainMaterialMonthPlan", params: JSON.stringify(rows) });
        });
        //导出订单数据
        $('#btnExportOrder').on("click", function () {
                var rows = $("#gdMfgOrderInfo").datagrid("getRows");
                if (rows.length === 0) {
                    displayMessage("请查询数据", false);
                    return false;
                }
                var datas = rows.map(function (item) {
                    return {
                        MFGORDERNAME: item.MFGORDERNAME,
                        PRODUCTNAME:item.PRODUCTNAME,
                        PRODUCTDESC:item.PRODUCTDESC,
                        WORKFLOWSTEPNAME:item.WORKFLOWSTEPNAME,
                        QTY:item.QTY,
                        PLANNEDSTARTDATE:item.PLANNEDSTARTDATE,
                        PLANNEDCOMPLETIONDATE:item.PLANNEDCOMPLETIONDATE
                    }
                });
                FileDownLoad(page.url, { action: "ExportMainMaterialMonthPlan", params: JSON.stringify(rows) });
        });
        //初始化默认日期
        $('#txtPlanStartDate').datebox('setValue',new Date().toDateString());
        $('#txtPlanEndDate').datebox('setValue',dayjs().add(35,'day').format('YYYY-MM-DD'));
    },
    //查询
    searchData: function () {
        var params = {
            action: "GetMainMaterialsMonthPlanData"
        };
        var queryFormData = $("#queryForm").serializeArray();
        $.each(queryFormData, function () {
            params[this.name] = this.value;
        });
        page.post(page.url, params, true, function (res) {
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            $("#gdMfgOrderInfo").datagrid('loadData', { rows: res.DBTable });
            $("#gdMaterialInfo").datagrid('loadData', { rows: res.ReturnData });
        });
    },
    //禁用页面按钮
    disableBtn: function () {
        $("#mainSec").find(".easyui-linkbutton").each(function () {
            $(this).linkbutton('disable');
        });
    },
    //启用页面按钮
    enableBtn: function () {
        $("#mainSec").find(".easyui-linkbutton").each(function () {
            $(this).linkbutton('enable');
        });
    },
    //清除页面（查询区域，列表区域）
    clearPage: function (query, list) {
        if (query) {
            $("#txtMfgOrderName_qf").textbox("clear");
            $("#txtProductName_qf").textbox("clear");
        }
        if (list) {
            clearEasyuiDataGrid("gdMfgOrderInfo"); //清空列表
            clearEasyuiDataGrid("gdMaterialInfo"); //清空列表
        }
    },
    //post数据（路径，参数，是否异步，成功返回方法）
    post: function (url, param, async, callback) {
        $.ajax({
            type: "Post",
            url: url,
            data: param,
            cashe: false,
            async: async,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
                $("body").find(".easyui-linkbutton").each(function () {
                    $(this).linkbutton('enable');
                });
            }
        });
    }
};
//弹窗编辑对象
var editPage = {
    materialID: "",
    init: function () {
        editPage.clearPage();
        editPage.bindPageData();
    },
    bind: function () {
        //规则弹窗保存
        $('#btnSave').on("click", function () {
            editPage.saveData();
        });
        //规则弹窗取消
        $('#btnCancel').on("click", function () {
            $('#dg').dialog("close");
        });
    },
    //绑定页面数据（编辑）
    bindPageData:function(){
        if(editPage.materialID !== ""){
            page.post(page.url, {action:"GetMaterialsConsumeInfoByID",materialID:editPage.materialID}, true, function (res) {
            if (!res.Result) {
                displayMessage(res.Message, res.Result);
                return;
            }
            $("#txtMaterialName_mf").textbox({ readonly: true });
            $("#txtMaterialName_mf").textbox("setValue",res.DBTable[0]["MATERIALNAME"]);
            $("#txtMaterialDesc_mf").textbox("setValue",res.DBTable[0]["MATERIALDESC"]);
            $("#sltMaterialCategory_mf").combobox("setValue",res.DBTable[0]["MATERIALCATEGORY"]);
            $("#txtLastYearConsumeNum_mf").numberbox("setValue",res.DBTable[0]["LASTYEARCONSUMENUM"]);
            $("#txtCalculateUnit_mf").textbox("setValue",res.DBTable[0]["CALCULATEUNIT"]);
            $("#txtRemark_mf").textbox("setValue",res.DBTable[0]["REMARK"]);
        });
        }
    },
    //保存数据
    saveData: function () {
        var vaild = $('#dgMaterialForm').form('validate');
        if (vaild === false) {
            displayMessage("请填写必填项", false);
            return;
        }
        var params = {
            materialID: editPage.materialID
        };
        var dgformData = $("#dgMaterialForm").serializeArray();
        $.each(dgformData, function () {
            params[this.name] = this.value;
        });
        page.post(page.url, { action: "SaveAssistMaterialsConsumeInfo", params: JSON.stringify(params) }, true, function (res) {
            if (res.Result) {
                $('#dg').dialog("close");
                page.searchData();
            }
            displayMessage(res.Message, res.Result);
        });
    },
    //清空页面数据
    clearPage: function () {
        $("#txtMaterialName_mf").textbox("clear");
        $("#txtMaterialDesc_mf").textbox("clear");
        $("#sltMaterialCategory_mf").combobox("clear");
        $("#txtLastYearConsumeNum_mf").numberbox("clear");
        $("#txtCalculateUnit_mf").textbox("clear");
        $("#txtRemark_mf").textbox("clear");
    }
};
//导入对象
var importPage = {
    //绑定事件
    bind:function(){
        $("#importTable").datagrid({
            columns: [[
                { field: 'ResultMessage', title: '导入结果', width: 300,formatter: function (value, row, index){
                    if (row.IsResult) {
                        return "<span color='blue'>" + value + "</span>";
                    }else
                    {
                        return "<span color='red'>" + value + "</span>";
                    }
                 }
                 },
                 { field: '物料编码', title: '物料编码', width: 100 },
                 { field: '物料名称', title: '物料名称', width: 60 },
                 { field: '类别', title: '类别', width: 80 },
                 { field: '上年度消耗量', title: '上年度消耗量', width: 80 },
                 { field: '计量单位', title: '计量单位', width: 80 },
                 { field: '备注', title: '备注', width: 80 }
	           ]] 
        });
        // //导入模板下载
        // $('#btnInportModelDL').on("click", function () {
        //     window.open(page.rootPath + "/Temp2/导入模板/自动开卡规则维护导入模板.xlsx");
        // });
        // //导出数据
        // $('#btnExportRule').on("click", function () {
        //     var params = {
        //         action: "ExportAutoStartRuleToExcel"
        //     };
        //     var queryFormData = $("#queryForm").serializeArray();
        //     $.each(queryFormData, function () {
        //         params[this.name] = this.value;
        //     });
        //     FileDownLoad(page.url, params);
        // });
        importPage.uploader();
    },
    //导入组件初始化
    uploader: function () {
        var uploaderSeq = WebUploader.create({
            // swf文件路径
            swf: page.rootPath + "/Content/webuploader/Uploader.swf",
            // 文件接收服务端。
            server: page.url,
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#btnImport',
            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            formData: {
                    action: "ImportAssistMaterialsConsume",
                },
            accept: {
                    title: 'Excel',
                    extensions: 'xlsx,xls',
                    mimeTypes: 'excel/*'
                },
        });
        // 当有文件被添加进队列的时候，每次只传一个文件
        uploaderSeq.on('fileQueued', function (file) {
            clearMessage();
            uploaderSeq.upload();
            $.messager.progress({ text: '', msg: '处理中...' });
        });
        //上传成功
        uploaderSeq.on('uploadSuccess', function (file, response) {
            clearMessage();
            var result = response;
            $.messager.progress('close');
            if(result.Result){
                importPage.loadResultData(result.DBTable);
            }
            displayMessage(result.Message, result.Result);
            var f = uploaderSeq.getFile(file.id); //找到上传的文件
            uploaderSeq.removeFile(f, true); //将其从队列中的删掉

        });
        //上传失败
        uploaderSeq.on('uploadError', function (file) {
            displayMessage("上传失败", false);
            var f = uploaderSeq.getFile(file.id); //找到上传的文件
            uploaderSeq.removeFile(f, true); //将其从队列中的删掉
            $.messager.progress('close');
        });
    },
    //导入结果列表
    loadResultData:function(data){
          $('#dgImport').dialog({
            title: '导入结果',
            top:50,
            width: '700px',
            height: '500px',
            closed: false,
            cache: false,
            modal: true,
            buttons:[{
				    text:'关闭',
				    handler:function(){$('#dgImport').dialog('close');}
			    }]
            });
           $("#importTable").datagrid('loadData',data);
    }
};
$(function () {
    page.init();
});
</script>
